﻿using Common.Communal;
using MediatR;
using System.Api.Write.Applications.Commands.Permissions;
using System.Services.Permissions;

namespace System.Api.Write.Applications.CommandHandlers.Permissions
{
    /// <summary>
    /// 删除权限命令处理程序
    /// </summary>
    public class PermissionDeleteCommandHandler : IRequestHandler<PermissionDeleteCommand, ApiResult<int>>
    {
        /// <summary>
        /// 权限服务
        /// </summary>
        private readonly IPermissionService service;
        /// <summary>
        /// 构造函数，注入权限服务
        /// </summary>
        /// <param name="service">权限服务</param>
        public PermissionDeleteCommandHandler(IPermissionService service)
        {
            this.service = service;
        }

        /// <summary>
        /// 处理删除权限命令
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回结果</returns>
        public async Task<ApiResult<int>> Handle(PermissionDeleteCommand request, CancellationToken cancellationToken)
        {
            return await service.Delete(request.Id);
        }
    }
}
